package com.bt.lms.ui.page.first;

import com.bt.lms.ui.page.first.action.LogonBtn;
import com.bt.lms.main.BotLmsApp;
import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * 登录界面
 */
public class Login extends VBox {

    /**
     * 窗口
     */
    private final Stage stage;

    /**
     * 构建首页
     * @param stage 窗口
     */
    public Login(Stage stage){

        //维护
        this.stage = stage;
        Integer wight = BotLmsApp.WIGHT;
        Integer height = BotLmsApp.HEIGHT;
        this.setPrefWidth(wight);
        this.setPrefHeight(height);
        int smallWight = 250;

        //布局
        Insets insets = new Insets(10);
        this.setPadding(insets);
        this.setSpacing(20);
        this.setAlignment(Pos.CENTER);

        //组件（系统名称）
        Label sysNameLab = new Label("博添教学管理系统");
        this.getChildren().add(sysNameLab);

        //组件（用户名）
        TextField idTF = new TextField("李毅");
        idTF.setPromptText("用户名");
        idTF.setMaxWidth(smallWight);
        this.getChildren().add(idTF);

        //组件（密码）
        PasswordField passwordTF = new PasswordField();
        passwordTF.setText("20230522");
        passwordTF.setPromptText("密码");
        passwordTF.setMaxWidth(smallWight);
        this.getChildren().add(passwordTF);

        //组件（自动登录
        RadioButton radioButton = new RadioButton("下次自动登录");
        this.getChildren().add(radioButton);

        //组件（操作区
        MyHBox myHBox = operationInit(smallWight);
        this.getChildren().add(myHBox);

    }

    /**
     * 操作区域初始化
     * @param wight 宽度
     * @return 操作区域
     */
    private MyHBox operationInit(int wight) {

        //新建操作区域盒子
        MyHBox myHBox = new MyHBox();
        myHBox.setMaxWidth(wight);

        //布局
        myHBox.setSpacing(30);
        myHBox.setAlignment(Pos.CENTER);

        //组件（登录按钮）
        Button logonBtn = new Button("登录");
        logonBtn.setPadding(new Insets(5,10,5,10));
        myHBox.getChildren().add(logonBtn);
        LogonBtn logonBtnAction = new LogonBtn(stage);//事件
        logonBtn.setOnAction(logonBtnAction);
        //样式
        Color color = Color.rgb(63, 139, 186);
        Color toColor = Color.rgb(34, 119, 168);
        BtnStyle.gradualChangeBack(logonBtn,color,toColor);
        logonBtn.setCursor(Cursor.HAND);

        return myHBox;

    }
}
